var app = getApp();
const pathUrl = app.globalData.pathUrl;
const common = require('../../utils/common.js')

Page({
  data: {
    pathUrl: pathUrl,
    orderNo: '',
    array: ['身份证', '护照', '军官证', '士兵证', '回乡证', '临时身份证', '户口本', '其他', '警官证'],
    number: '0',
    pickerIndex: '0',
    orderPeriod: '身份证',
    array1: ['男', '女'],
    array2: ['未婚(无配偶)', '已婚(有配偶)', '分居', '离异', '丧偶', '其他'],
    array3: ['博士及以上', '硕士研究生', '大学本科', '大学专科/电大', '中专', '技工学校', '高中', '初中', '小学及以下'],
    array4: ['自取', '寄送单位地址', '寄送住宅地址'],
    array5: ['自有住房', '分期付款购房', '租房', '其他', '集体宿舍', '单位分配'],
    array6: ['国家主席、副主席、总理级副总理、国务委员级', '部、省级、副部、副省级', '董事/司、局、地、厅级', '总经理/县处级', '科级/部门经理', '职员/科员级'],
    array7: ['国有', '集体', '国有控股', '集体控股', '三资', '私营', '个体', '外贸', '股份合作', '其他股份制', '民营', '联营', '乡镇企业', '其他'],
    array8: ['公务员', '事业单位员工', '职员', '军人', '自由职业者', '工人', '农民', '邮电通讯行业职员', '房地产行业职员', '交通运输行业职员', '法律/司法行业职员', '文化/娱乐/体育行业职员', '媒介/广告行业职员', '科研/教育行业职员', '学生', '计算机/网络行业职员', '商业贸易行业职员', '银行/金融/证券/投资行业职员', '税务行业职员', '咨询行业职员', '社会服务行业职员', '旅游/饭店行业职员', '健康/医疗服务行业职员', '管理人员', '技术人员', '文体明星', '无职业', '私人业主'],
    array9: ['有', '无'],
    array10: ['父子', '母子', '兄弟姐妹', '亲属', '夫妻', '同学', '同乡', '朋友', '同事'],
    array11: ['是', '否'],
    number11: '1',
    pickerIndex11: '0',
    orderPeriod11: '是',
    number9: '1',
    pickerIndex9: '1',
    orderPeriod9: '无',
    flag: true,
    date1: '2020-01',
    date2: '2020-01-01',
    primnat: '中国', //值为156
    isSubmit: true,
    region: ['福建省', '泉州市', '石狮市'],
    region1: ['福建省', '泉州市', '石狮市'],
    bankCode: '0140808524',
    assurerNo: 'S14081592',
    platNo: 'qzyt',
    busiCode: '1001',
    productType: '1',
    downloadMode: '1',

  },
  onLoad: function(e) {
    var openId = wx.getStorageSync('openId');
    var orderNo = e.orderNo;
    var date = common.getToday();
    this.setData({
      openId: openId,
      date: date,
      orderNo: orderNo
    })
    wx.setNavigationBarTitle({
      title: '开卡信息提交'
    })
    // this.getno();
    // this.getProAttList();
    this.getHrzxjj01();
  },
  getHrzxjj01:function(e){
    var that = this;
    var orderNo = that.data.orderNo;
    console.log(orderNo)
    wx.request({
      url: pathUrl + '/rest/hrzxjj01Controller/list/'+that.data.openId,
      data:{
        pageNumber:'1',
        pageSize  :'100',
        orderNo: that.data.orderNo
      },
      success:function(e){
        console.log(e)
        var list =e.data.data[0]
        console.log("list======="+JSON.stringify(list) );
        var statdate = list.endDate
        console.log(typeof (statdate))
        var str1 = statdate.replace('.', '-');
        console.log(str1);
        var statdate = str1.replace('.', '-')
        console.log(statdate)
        that.setData({
          custcode: list.idCard,
          chnsname: list.userName,
          mvblno: list.phoneNum,
          date2: statdate,
          yearincome:list.yearincome,
        })
      }
    })
  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindDateChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date2: e.detail.value
    })
  },
  getDateTime: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date1: e.detail.value
    })
  },
  bindRelationship: function(e) {
    var index = e.detail.value;
    var orderPeriod = this.data.array[index];
    var number = null;
    console.log(index)
    if (index == '8') {
      this.setData({
        number: '9',
        pickerIndex: index,
        orderPeriod: orderPeriod
      })
    } else {
      this.setData({
        number: index,
        pickerIndex: index,
        orderPeriod: orderPeriod
      })
    }
  },
  bindRelationship1: function(e) {
    var index = e.detail.value;
    var orderPeriod1 = this.data.array1[index];
    var number1 = Number(index) + 1;
    this.setData({
      number1: number1,
      pickerIndex1: index,
      orderPeriod1: orderPeriod1
    })
  },
  bindRelationship2: function(e) {
    var index = e.detail.value;
    var orderPeriod2 = this.data.array2[index];
    var number2 = Number(index) + 1;
    console.log(index)
    this.setData({
      number2: number2,
      pickerIndex2: index,
      orderPeriod2: orderPeriod2
    })
  },
  bindRelationship3: function(e) {
    var index = e.detail.value;
    var orderPeriod3 = this.data.array3[index];
    var number3 = Number(index) + 1;
    console.log(index)
    this.setData({
      number3: number3,
      pickerIndex3: index,
      orderPeriod3: orderPeriod3
    })
  },
  bindRelationship4: function(e) {
    var index = e.detail.value;
    var orderPeriod4 = this.data.array4[index];
    var number4 = Number(index) + 1;
    console.log(index)
    this.setData({
      number4: number4,
      pickerIndex4: index,
      orderPeriod4: orderPeriod4
    })
  },
  bindRelationship5: function(e) {
    var index = e.detail.value;
    var orderPeriod5 = this.data.array5[index];
    var number5 = Number(index) + 1;
    console.log(index)
    this.setData({
      number5: number5,
      pickerIndex5: index,
      orderPeriod5: orderPeriod5
    })
  },
  bindRelationship6: function(e) {
    var index = e.detail.value;
    var orderPeriod6 = this.data.array6[index];
    var number6 = Number(index) + 1;
    console.log(index)
    this.setData({
      number6: number6,
      pickerIndex6: index,
      orderPeriod6: orderPeriod6
    })
  },
  bindRelationship7: function(e) {
    var index = e.detail.value;
    var orderPeriod7 = this.data.array7[index];
    var number7 = null;
    if (index == '0') {
      this.setData({
        number7: '10',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '1') {
      this.setData({
        number7: '20',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '2') {
      this.setData({
        number7: '30',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '3') {
      this.setData({
        number7: '40',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '4') {
      this.setData({
        number7: '50',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '5') {
      this.setData({
        number7: '60',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '6') {
      this.setData({
        number7: '70',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '7') {
      this.setData({
        number7: '80',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '8') {
      this.setData({
        number7: '90',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '9') {
      this.setData({
        number7: '100',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '10') {
      this.setData({
        number7: '110',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '11') {
      this.setData({
        number7: '120',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '12') {
      this.setData({
        number7: '130',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
    if (index == '13') {
      this.setData({
        number7: '190',
        pickerIndex7: index,
        orderPeriod7: orderPeriod7
      })
    }
  },
  bindRelationship8: function(e) {
    var index = e.detail.value;
    var orderPeriod8 = this.data.array8[index];
    var number8 = null;
    if (index == '0') {
      this.setData({
        number8: '1',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '1') {
      this.setData({
        number8: '2',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '2') {
      this.setData({
        number8: '3',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '3') {
      this.setData({
        number8: '4',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '4') {
      this.setData({
        number8: '5',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '5') {
      this.setData({
        number8: '6',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '6') {
      this.setData({
        number8: '7',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '7') {
      this.setData({
        number8: '10',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '8') {
      this.setData({
        number8: '11',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '9') {
      this.setData({
        number8: '12',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '10') {
      this.setData({
        number8: '13',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '11') {
      this.setData({
        number8: '14',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '12') {
      this.setData({
        number8: '15',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '13') {
      this.setData({
        number8: '16',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '14') {
      this.setData({
        number8: '17',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '15') {
      this.setData({
        number8: '18',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '16') {
      this.setData({
        number8: '19',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '17') {
      this.setData({
        number8: '20',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '18') {
      this.setData({
        number8: '21',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '19') {
      this.setData({
        number8: '22',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '20') {
      this.setData({
        number8: '23',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '21') {
      this.setData({
        number8: '24',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '22') {
      this.setData({
        number8: '25',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '23') {
      this.setData({
        number8: '26',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '24') {
      this.setData({
        number8: '27',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '25') {
      this.setData({
        number8: '28',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '26') {
      this.setData({
        number8: '29',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
    if (index == '27') {
      this.setData({
        number8: '30',
        pickerIndex8: index,
        orderPeriod8: orderPeriod8
      })
    }
  },
  bindRelationship9: function(e) {
    var index = e.detail.value;
    var orderPeriod9 = this.data.array9[index];
    var number9 = null;
    console.log(index)
    this.setData({
      number9: index,
      pickerIndex9: index,
      orderPeriod9: orderPeriod9
    })
  },
  bindRelationship10: function(e) {
    var index = e.detail.value;
    var orderPeriod10 = this.data.array10[index];
    var number10 = Number(index) + 1;
    console.log(index)
    this.setData({
      number10: number10,
      pickerIndex10: index,
      orderPeriod10: orderPeriod10
    })
  },
  bindRelationship11: function(e) {
    var index = e.detail.value;
    var orderPeriod11 = this.data.array11[index];
    var number11 = Number(index) + 1;
    this.setData({
      number11: number11,
      pickerIndex11: index,
      orderPeriod11: orderPeriod11
    })
  },
  getno: function() {
    var that = this;
    wx.request({
      url: pathUrl + '/rest/base/getno/' + that.data.proNo,
      success: function(res) {
        if (res.data.ok || res.data.data) {
          that.setData({
            orderNo: res.data.data
          })
        } else {
          wx.showModal({
            title: '提示',
            content: '获取数据失败',
            confirmColor: '#7aa6d1',
            showCancel: false
          })
        }
      }
    })
  },
  bankCode: function(e) {
    this.setData({
      bankCode: e.detail.value
    })
  },
  assurerNo: function(e) {
    this.setData({
      assurerNo: e.detail.value
    })
  },
  platNo: function(e) {
    this.setData({
      platNo: e.detail.value
    })
  },
  busiCode: function(e) {
    this.setData({
      busiCode: e.detail.value
    })
  },
  productType: function(e) {
    this.setData({
      productType: e.detail.value
    })
  },
  orderNo: function(e) {
    this.setData({
      orderNo: e.detail.value
    })
  },
  custcode: function(e) {
    this.setData({
      custcode: e.detail.value
    })
  },
  chnsname: function(e) {
    this.setData({
      chnsname: e.detail.value
    })
  },
  engname: function(e) {
    this.setData({
      engname: e.detail.value
    })
  },
  drawzono: function(e) {
    this.setData({
      drawzono: e.detail.value
    })
  },
  drawbrno: function(e) {
    this.setData({
      drawbrno: e.detail.value
    })
  },
  homestat: function(e) {
    this.setData({
      homestat: e.detail.value
    })
  },
  hprovince: function(e) {
    this.setData({
      hprovince: e.detail.value
    })
  },
  hcity: function(e) {
    this.setData({
      hcity: e.detail.value
    })
  },
  hcounty: function(e) {
    this.setData({
      hcounty: e.detail.value
    })
  },
  haddress: function(e) {
    this.setData({
      haddress: e.detail.value
    })
  },
  homezip: function(e) {
    this.setData({
      homezip: e.detail.value
    })
  },
  mvblno: function(e) {
    this.setData({
      mvblno: e.detail.value
    })
  },
  email: function(e) {
    this.setData({
      email: e.detail.value
    })
  },
  unitname: function(e) {
    this.setData({
      unitname: e.detail.value
    })
  },
  cophozono: function(e) {
    this.setData({
      cophozono: e.detail.value
    })
  },
  cophoneno: function(e) {
    this.setData({
      cophoneno: e.detail.value
    })
  },
  cprovince: function(e) {
    this.setData({
      cprovince: e.detail.value
    })
  },
  ccity: function(e) {
    this.setData({
      ccity: e.detail.value
    })
  },

  ccounty: function(e) {
    this.setData({
      ccounty: e.detail.value
    })
  },
  caddress: function(e) {
    this.setData({
      caddress: e.detail.value
    })
  },
  corpzip: function(e) {
    this.setData({
      corpzip: e.detail.value
    })
  },
  yearincome: function(e) {
    this.setData({
      yearincome: e.detail.value
    })
  },
  relaphone1: function(e) {
    this.setData({
      relaphone1: e.detail.value
    })
  },
  reltphzon1: function(e) {
    this.setData({
      reltphzon1: e.detail.value
    })
  },
  reltmobl1: function(e) {
    this.setData({
      reltmobl1: e.detail.value
    })
  },
  reltname1: function(e) {
    this.setData({
      reltname1: e.detail.value
    })
  },
  primnat: function(e) {
    this.setData({
      primnat: e.detail.value
    })
  },
  almebno: function(e) {
    this.setData({
      almebno: e.detail.value
    })
  },
  outcardno1: function(e) {
    this.setData({
      outcardno1: e.detail.value
    })
  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
  bindRegionChange1: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region1: e.detail.value
    })
  },
  submitBtn: function() {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    if (that.data.isSubmit) {
      that.setData({
        isSubmit: false
      });
      var str = that.data.date1;
      date1 = str.replace(/-/g, ""); 
      console.log(date1)
      var data = {
        // custsort: that.data.number,
        // assurerNo: that.data.assurerNo,
        // platNo: that.data.platNo,
        homezip: that.data.homezip,

        bankCode: that.data.bankCode,
        assurerNo: that.data.assurerNo,
        platNo: that.data.platNo,
        busiCode: that.data.busiCode,
        productType: that.data.productType,
        orderNo: that.data.orderNo,
        custsort: that.data.number,
        custcode: that.data.custcode,
        chnsname: that.data.chnsname,
        engname: that.data.engname,
        sex: that.data.number1,
        mrtlstat: that.data.number2,
        edulvl: that.data.number3,
        drawmode: that.data.number4,
        drawzono: that.data.drawzono,
        drawbrno: that.data.drawbrno,
        homestat: that.data.number5,
        hprovince: that.data.region[0],
        hcity: that.data.region[1],
        hcounty: that.data.region[2],
        haddress: that.data.haddress,
        indate: that.data.date,
        mvblno: that.data.mvblno,
        email: that.data.email,
        unitname: that.data.unitname,
        duty: that.data.number6,
        cophozono: that.data.cophozono,
        cophoneno: that.data.cophoneno,
        cprovince: that.data.region1[0],
        ccity: that.data.region1[1],
        ccounty: that.data.region1[2],
        caddress: that.data.caddress,
        corpzip: that.data.corpzip,
        joindate: date1,
        yearincome: that.data.yearincome,
        modelcode: that.data.number7,
        occptn: that.data.number8,
        carstat: that.data.number9,
        reltname1: that.data.reltname1,
        reltphzon1: that.data.reltphzon1,
        reltship1: that.data.number10,
        relaphone1: that.data.relaphone1,
        reltmobl1: that.data.reltmobl1,
        statdate: that.data.date2,
        primnat: '156',
        cstsign: that.data.number11,
        almebno: that.data.almebno,
        outcardno1: that.data.outcardno1,
      };
      console.log("data:" + JSON.stringify(data));
      wx.request({
        url: pathUrl + '/rest/hrkkxxController',
        data: data,
        method: 'POST',
        success: function(res) {
          console.log(res.data)
          if (res.data.ok) {
            // that.setData({
            //   isSubmit: true
            // });
            wx.request({
              url: pathUrl + '/rest/hrkkxxController/postkk/'+that.data.orderNo,
              method:'GET',
              success:function(e){
                console.log(e)
                wx.hideLoading();
                if(e.data.ok){
                  wx.showModal({
                    title: '提示',
                    content: '开卡信息提交成功',
                    showCancel: false,
                    success: function () {
                      wx.navigateBack({
                        delet: 1
                      })
                    }
                  })
                }else{
                  wx.showModal({
                    title: '提示',
                    content: '上传失败，请联系工作人员',
                    showCancel: false,
                    success: function () {
                      wx.navigateBack({
                        delet: 1
                      })
                    }
                  })
                }
              }
            })
            // wx.showToast({
            //   title: '提交成功',
            //   duration: 1000,
            //   mask: true,
            //   success: function() {
            //     setTimeout(function () {
            //       wx.switchTab({
            //         url: "/pages/index/index"
            //       })
            //     }, 1000);
            //   }
            // })
          } else {
            that.setData({
              isSubmit: true
            });
            wx.showToast({
              title: '提交失败',
              icon: 'none',
              mask: true,
              duration: 1000
            })
          }
        }
      })
    } else {
      wx.showToast({
        title: '请勿重复提交',
        icon: 'none',
        mask: true,
        duration: 1000
      })
    }
  },

  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})